Skip to content

fix: correct regex patterns in roo integration tests#20

Open
johnlindquist wants to merge 1 commit into
mainfrom
claude/issue-18-20251005-1746
Open

fix: correct regex patterns in roo integration tests#20
johnlindquist wants to merge 1 commit into
mainfrom
claude/issue-18-20251005-1746

Conversation

@johnlindquist

@johnlindquist johnlindquist commented Oct 5, 2025

Copy link
Copy Markdown
Owner
  • Fix newline expectation: tests expected two newlines after frontmatter closing --- but export produces one
  • Fix field order dependency: split assertions to avoid assuming YAML field order
  • Fixes line 126-127 and 205 in test/integration/roo.test.ts

Summary by CodeRabbit

  • New Features
    • Exported content now enforces a description field in frontmatter, improving metadata completeness.
  • Bug Fixes
    • Standardized exported output by removing the extra blank line between frontmatter and markdown content for consistent formatting across tools.
  • Tests
    • Updated integration tests to validate the presence of the description field.
    • Adjusted expectations to reflect the new frontmatter-to-content boundary without a blank line.

- Fix newline expectation: tests expected two newlines after frontmatter closing --- but export produces one
- Fix field order dependency: split assertions to avoid assuming YAML field order
- Fixes line 126-127 and 205 in test/integration/roo.test.ts

Co-authored-by: John Lindquist <johnlindquist@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 5, 2025

Copy link
Copy Markdown

Walkthrough

Updated integration tests to reflect a change in exported markdown formatting: the YAML frontmatter now directly precedes content without a blank line. Added an assertion to ensure a description field exists in the frontmatter. Adjusted CLI export test expectations accordingly.

Changes

Cohort / File(s) Summary
Integration tests: frontmatter boundary and metadata
test/integration/roo.test.ts
Updated assertions to remove required blank line after ---, expect content to follow immediately, and verify description exists in frontmatter.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A rabbit taps tests with careful cheer,
Frontmatter hugs content, crystal-clear.
A description pops in, tidy and neat—
YAML and Markdown finally meet.
Hop, hop, commit! With whiskers alight,
The tests now pass in the moonlit night. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly states the nature of the change—fixing regex patterns—and specifies the affected component (roo integration tests), matching the updates in the test file to frontmatter and content assertions.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/issue-18-20251005-1746

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Oct 5, 2025

Copy link
Copy Markdown

Code Review: PR #20 - Fix regex patterns in roo integration tests

Summary

This PR fixes test assertions in the Roo integration tests by correcting regex patterns to match the actual output format produced by the gray-matter library and by removing field order dependencies in YAML frontmatter assertions.

✅ Positive Aspects

  1. Correct Fix: The changes properly address the root cause - gray-matter.stringify() produces a single newline after the frontmatter closing delimiter (---\n), not double newlines (---\n\n). The updated regex patterns correctly reflect this behavior.

  2. Improved Test Robustness: Splitting the assertion on line 126-127 into two separate assertions removes the dependency on YAML field ordering, which is implementation-dependent and can vary. This makes the tests more reliable across different YAML serialization implementations.

  3. Clear Documentation: The PR description clearly explains what was fixed and why, making it easy for reviewers to understand the changes.

  4. Minimal Scope: The changes are surgical and only touch the problematic assertions, following the principle of least change.

🔍 Code Quality Analysis

Changes:

  • Line 126: Changed /^---[\s\S]*alwaysApply: true[\s\S]*description: Exported public rule[\s\S]*---\n\n#/ to /^---[\s\S]*alwaysApply: true[\s\S]*---\n#/
  • Line 127: Added separate assertion /^---[\s\S]*description: Exported public rule[\s\S]*---/
  • Line 205: Changed /^---[\s\S]*alwaysApply: true[\s\S]*---\n\n#/ to /^---[\s\S]*alwaysApply: true[\s\S]*---\n#/

Observations:

  1. The regex pattern fix (\n\n\n) aligns with the actual output from exportToRoo() in src/exporters.ts:518, which uses matter.stringify() with the custom YAML parser.

  2. The split assertion approach (lines 126-127) is a best practice for testing YAML frontmatter where field order is not guaranteed.

🐛 Potential Issues

None identified. The changes are appropriate and correctly fix the test failures.

⚡ Performance Considerations

No performance impact - these are test-only changes.

🔒 Security Concerns

No security concerns identified.

🧪 Test Coverage

Good: The PR fixes existing test coverage that was incorrectly asserting against the wrong format. The tests now properly validate:

  • Frontmatter format (single newline after closing delimiter)
  • Content preservation in export operations
  • Field presence without order dependency

Suggestion: Consider adding an explicit test case that validates the exact format of the exported file to document the expected output format. For example:

```typescript
it('exports with correct frontmatter format (single newline)', () => {
const rules: RuleBlock[] = [{
metadata: { id: 'format-test', alwaysApply: true },
content: '# Content'
}]

exportToRoo(rules, tempDir)
const content = readFileSync(join(tempDir, '.roo', 'rules', 'format-test.md'), 'utf-8')

// Should have exactly one newline after closing ---
expect(content).toMatch(/^---\nalwaysApply: true\n---\n# Content$/)
})
```

📝 Additional Observations

  1. Gray-matter behavior: The behavior of producing a single newline after the frontmatter delimiter is standard for gray-matter v4.0.3 (as used in package.json). This is working as designed.

  2. Test pattern consistency: I noticed similar regex patterns in the test file. You may want to audit the entire test suite for other instances of the ---\n\n pattern that might need the same fix.

  3. YAML field order: The custom YAML parser in src/yaml-parser.ts uses js-yaml's dump() function, which doesn't guarantee field order. The split assertion approach is the right solution.

✨ Recommendations

  1. Merge with confidence - This PR correctly fixes the test failures.

  2. Consider documenting the format - Add a comment in the test explaining why we expect a single newline, referencing the gray-matter library behavior.

  3. Audit similar patterns - Search for other test assertions using ---\n\n that may need similar fixes.

Verdict

LGTM ✅ - This is a clean, well-scoped fix that addresses real test failures. The changes are correct, improve test reliability, and have no negative impacts.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/integration/roo.test.ts (1)

126-127: LGTM! Well-structured test assertions.

The changes correctly address the PR objectives:

  • Line 126 now expects a single newline after the frontmatter closing --- instead of two
  • Line 127 adds an independent assertion for the description field, eliminating dependency on YAML field order

The regex patterns are accurate and the split-assertion approach improves test robustness.

Optional: Consider using the dotall flag for improved readability (ES2018+).

If the codebase targets ES2018 or later, you could replace [\s\S]* with .* and add the s flag:

-    expect(publicContent).toMatch(/^---[\s\S]*alwaysApply: true[\s\S]*---\n# Exported Public Content/)
-    expect(publicContent).toMatch(/^---[\s\S]*description: Exported public rule[\s\S]*---/)
+    expect(publicContent).toMatch(/^---.*alwaysApply: true.*---\n# Exported Public Content/s)
+    expect(publicContent).toMatch(/^---.*description: Exported public rule.*---/s)

This makes the patterns more readable while maintaining identical functionality.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdf4b11 and 9da8379.

📒 Files selected for processing (1)
  • test/integration/roo.test.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: claude-review
🔇 Additional comments (1)
test/integration/roo.test.ts (1)

205-205: LGTM! Consistent with other formatting changes.

This change correctly updates the CLI export test to expect a single newline after the frontmatter closing ---, consistent with the changes on line 126. The regex pattern accurately validates the exported content format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant